package com.atguigu.flink.chapter02;

import org.apache.flink.api.common.typeinfo.Types;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2022/1/11 10:06
 */
public class Flink04_UnBounded_WC_Lambda {
    public static void main(String[] args) throws Exception {
        System.out.println("xxxxx");
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        
        env
            .socketTextStream("hadoop162", 9999)
            .flatMap((String line, Collector<String> out) -> {
                for (String word : line.split(" ")) {
                    out.collect(word);
                    
                }
                
            }).returns(Types.STRING)
            .map(word -> Tuple2.of(word, 1L)).returns(Types.TUPLE(Types.STRING, Types.LONG))
            .keyBy(t -> t.f0)
            .sum(1)
            .print();
        
        env.execute();  // 如果是流式, 执行流式环境
    }
}
/*
拉姆达表达式

是一种函数式编程  1.8 新增的功能


 */
